#include "RegexHeaders.h"

int StrToLower(string& in) {
    try
    {
        regex pattern(".*[A-Z].*");
        //ReplaceByRegex(in, pattern04, "\L$1");
        smatch results;
        if (regex_match(in, results, pattern)) {
            for (auto it = results.begin(); it != results.end(); ++it)
            {
                string tp = it->str();
                std::transform(tp.begin(), tp.end(), tp.begin(), ::tolower);
                cout << tp << endl;
                in = tp;
            }
        }
        else {
            cout << "match failed: " << in << endl;
            return -1;
        }
    }
    catch (const std::exception& err)
    {
        std::cout << err.what() << std::endl;
        return -1;
    }
	return 0;
}

int StrToUpper(string& in)
{
    try
    {
        regex pattern(".*[a-z].*");
        //ReplaceByRegex(in, pattern04, "\L$1");
        smatch results;
        if (regex_match(in, results, pattern)) {
            for (auto it = results.begin(); it != results.end(); ++it)
            {
                string tp = it->str();
                std::transform(tp.begin(), tp.end(), tp.begin(), ::toupper);
                cout << tp << endl;
            }
        }
        else {
            cout << "match failed: " << in << endl;
            return -1;
        }
    }
    catch (const std::exception& err)
    {
        std::cout << err.what() << std::endl;
        return -1;
    }
    return 0;
}
